package com.project.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.server.mapper.DiningTableMapper;
import com.project.server.model.DiningTable;
import com.project.server.service.DiningTableService;
import com.project.server.vo.DiningTableVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
@RequiredArgsConstructor
public class DiningTableServiceImpl implements DiningTableService {

    private final DiningTableMapper diningTableMapper;

    @Override
    public Page<DiningTableVO> page(Integer pageNum, Integer pageSize, String tableNumber, Long restaurantId, Integer status) {
        Page<DiningTable> page = new Page<>(pageNum, pageSize);
        return diningTableMapper.getDiningTablePage(page, tableNumber, restaurantId, status);
    }

    @Override
    public DiningTable getById(Long id) {
        return diningTableMapper.selectById(id);
    }

    @Override
    public void save(DiningTable diningTable) {
        diningTable.setStatus(0); // 默认空闲状态
        diningTableMapper.insert(diningTable);
    }

    @Override
    public void update(DiningTable diningTable) {
        diningTableMapper.updateById(diningTable);
    }

    @Override
    public void removeById(Long id) {
        diningTableMapper.deleteById(id);
    }

    @Override
    public void updateStatus(Long id, Integer status) {
        DiningTable table = new DiningTable();
        table.setId(id);
        table.setStatus(status);
        diningTableMapper.updateById(table);
    }

    @Override
    public List<DiningTable> getAvailableTables(Long restaurantId) {
        return diningTableMapper.getAvailableTables(restaurantId);
    }
} 